package pack5_clone;

import java.util.ArrayList;
import java.util.List;

class Human implements Cloneable{
    private String nose;
    private String mouth;
    private List<String> eyes = new ArrayList<String>();
    private List<String> ears = new ArrayList<String>();

    public Human(){
        this.nose = "nose";
        this.mouth = "mouth";
        this.eyes.add("leftEye");
        this.eyes.add("rightEye");
        this.ears.add("lefttEye");
        this.ears.add("rightEye");
    }

    @Override
    public Human clone(){
        Human human = null;
        try {
            human = (Human)super.clone();
        } catch (CloneNotSupportedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  //调用父类的clone,如果调用this.clone，则变成递归调用
        return human;
    }

    @Override
    public String toString() {
        return "Human{" +
                "nose='" + nose + '\'' +
                ", mouth='" + mouth + '\'' +
                ", eyes=" + eyes +
                ", ears=" + ears +
                '}';
    }
}

public class code001_clone {
    public static void main(String[] args) {
        Human human = new Human();
        System.out.print(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(human)) + " ");
        System.out.println(human);

        Human clone = human.clone();
        System.out.print(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(clone)) + " ");
        System.out.println(clone);
    }
}
